/*
 * Zhz.net Inc.
 * Copyright (c) 2010 All Rights Reserved.
 */
package com.ceicei.project.dal.ibatis;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.ceicei.project.dal.daointerface.CeiceiItemsPriceLogDAO;

// auto generated imports
import com.ceicei.project.dal.dataobject.CeiceiItemsPriceLogDO;
import org.springframework.dao.DataAccessException;
import java.util.List;
import java.util.Date;
import com.ceicei.project.dal.dataobject.CeiceiItemsPriceLogDO;
import java.util.Map;
import java.util.HashMap;

/**
 * An ibatis based implementation of dao interface <tt>com.ceicei.project.dal.daointerface.CeiceiItemsPriceLogDAO</tt>.
 *
 * This file is generated by <tt>paygw-dalgen</tt>, a DAL (Data Access Layer)
 * code generation utility specially developed for <tt>paygw</tt> project.
 * 
 * PLEASE DO NOT MODIFY THIS FILE MANUALLY, or else your modification may
 * be OVERWRITTEN by someone else. To modify the file, you should go to 
 * directory <tt>(project-home)/biz/dal/src/conf/dalgen</tt>, and 
 * find the corresponding configuration file (<tt>tables/ceicei_items_price_log.xml</tt>). 
 * Modify the configuration file according to your needs, then run <tt>paygw-dalgen</tt> 
 * to generate this file.
 *
 * @author Li Wei
 */
public class IbatisCeiceiItemsPriceLogDAO extends SqlMapClientDaoSupport implements CeiceiItemsPriceLogDAO {
	/**
	 *  Query DB table <tt>ceicei_items_price_log</tt> for records.
	 *
   	 *  <p>
   	 *  Description for this operation is<br>
   	 *  <tt></tt>
	 *  <p>
	 *  The sql statement for this operation is <br>
	 *  <tt>select * from ceicei_items_price_log where (id = ?)</tt>
	 *
	 *	@param id
	 *	@return CeiceiItemsPriceLogDO
	 *	@throws DataAccessException
	 */	 
    public CeiceiItemsPriceLogDO getById(long id) throws DataAccessException {
        Long param = new Long(id);

        return (CeiceiItemsPriceLogDO) getSqlMapClientTemplate().queryForObject("MS-CEICEI-ITEMS-PRICE-LOG-GET-BY-ID", param);

    }

	/**
	 *  Query DB table <tt>ceicei_items_price_log</tt> for records.
	 *
   	 *  <p>
   	 *  Description for this operation is<br>
   	 *  <tt></tt>
	 *  <p>
	 *  The sql statement for this operation is <br>
	 *  <tt>select * from ceicei_items_price_log where (itemid = ?)</tt>
	 *
	 *	@param itemid
	 *	@return List<CeiceiItemsPriceLogDO>
	 *	@throws DataAccessException
	 */	 
    public List<CeiceiItemsPriceLogDO> getByItemId(long itemid) throws DataAccessException {
        Long param = new Long(itemid);

        return getSqlMapClientTemplate().queryForList("MS-CEICEI-ITEMS-PRICE-LOG-GET-BY-ITEM-ID", param);

    }

	/**
	 *  Insert one <tt>CeiceiItemsPriceLogDO</tt> object to DB table <tt>ceicei_items_price_log</tt>, return primary key
	 *
   	 *  <p>
   	 *  Description for this operation is<br>
   	 *  <tt></tt>
	 *  <p>
	 *  The sql statement for this operation is <br>
	 *  <tt>insert into ceicei_items_price_log(id,itemid,price,price_type,source,createtime,smsed,smstime,mailed,mailtime) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)</tt>
	 *
	 *	@param ceiceiItemsPriceLog
	 *	@return long
	 *	@throws DataAccessException
	 */	 
    public long insert(CeiceiItemsPriceLogDO ceiceiItemsPriceLog) throws DataAccessException {
    	if (ceiceiItemsPriceLog == null) {
    		throw new IllegalArgumentException("Can't insert a null data object into db.");
    	}
    	
        getSqlMapClientTemplate().insert("MS-CEICEI-ITEMS-PRICE-LOG-INSERT", ceiceiItemsPriceLog);

        return ceiceiItemsPriceLog.getId();
    }

	/**
	 *  Query DB table <tt>ceicei_items_price_log</tt> for records.
	 *
   	 *  <p>
   	 *  Description for this operation is<br>
   	 *  <tt></tt>
	 *  <p>
	 *  The sql statement for this operation is <br>
	 *  <tt>select * from ceicei_items_price_log where (id IN (select max(id) id from ceicei_items_price_log where (itemid = ?)))</tt>
	 *
	 *	@param itemid
	 *	@return CeiceiItemsPriceLogDO
	 *	@throws DataAccessException
	 */	 
    public CeiceiItemsPriceLogDO getLastPriceByItemid(long itemid) throws DataAccessException {
        Long param = new Long(itemid);

        return (CeiceiItemsPriceLogDO) getSqlMapClientTemplate().queryForObject("MS-CEICEI-ITEMS-PRICE-LOG-GET-LAST-PRICE-BY-ITEMID", param);

    }

	/**
	 *  Update DB table <tt>ceicei_items_price_log</tt>.
	 *
   	 *  <p>
   	 *  Description for this operation is<br>
   	 *  <tt></tt>
	 *  <p>
	 *  The sql statement for this operation is <br>
	 *  <tt>update ceicei_items_price_log set smsed=?, smstime=? where (id = ?)</tt>
	 *
	 *	@param smsed
	 *	@param smstime
	 *	@param id
	 *	@return int
	 *	@throws DataAccessException
	 */	 
    public int updateSms(int smsed, Date smstime, long id) throws DataAccessException {
        Map param = new HashMap();

        param.put("smsed", new Integer(smsed));
        param.put("smstime", smstime);
        param.put("id", new Long(id));

        return getSqlMapClientTemplate().update("MS-CEICEI-ITEMS-PRICE-LOG-UPDATE-SMS", param);
    }

	/**
	 *  Update DB table <tt>ceicei_items_price_log</tt>.
	 *
   	 *  <p>
   	 *  Description for this operation is<br>
   	 *  <tt></tt>
	 *  <p>
	 *  The sql statement for this operation is <br>
	 *  <tt>update ceicei_items_price_log set mailed=?, mailtime=? where (id = ?)</tt>
	 *
	 *	@param mailed
	 *	@param mailtime
	 *	@param id
	 *	@return int
	 *	@throws DataAccessException
	 */	 
    public int updateMail(int mailed, Date mailtime, long id) throws DataAccessException {
        Map param = new HashMap();

        param.put("mailed", new Integer(mailed));
        param.put("mailtime", mailtime);
        param.put("id", new Long(id));

        return getSqlMapClientTemplate().update("MS-CEICEI-ITEMS-PRICE-LOG-UPDATE-MAIL", param);
    }

}